﻿namespace CV.Entities.Models
{
    using CV.Entities.Dto;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;

    public class SignupModel
    {
        public SignupModel()
        {

        }

        [Required]
        [StringLength(20)]
        [Display(Name = "Login", ResourceType = typeof(CV.Resources.Model.SignUpModel))]
        public string Login { get; set; }

        [Required]
        [Display(Name = "Password", ResourceType = typeof(CV.Resources.Model.SignUpModel))]
        [RegularExpression("((?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{6,20})",
            ErrorMessageResourceName = "PasswordErrorMessage",
            ErrorMessageResourceType = typeof(CV.Resources.Model.SignUpModel))]
        [DataType(DataType.Password)]
        public string Password { get; set; }

        [Required]
        [Display(Name = "PasswordConfirm", ResourceType = typeof(CV.Resources.Model.SignUpModel))]
        [Compare("Password",
            ErrorMessageResourceName = "PasswordMismatch",
            ErrorMessageResourceType = typeof(CV.Resources.Model.SignUpModel))]
        [DataType(DataType.Password)]
        public string PasswordConfirm { get; set; }

        [Required]
        [Display(Name = "FirstName", ResourceType = typeof(CV.Resources.Model.SignUpModel))]
        public string FirstName { get; set; }

        [Required]
        [Display(Name = "LastName", ResourceType = typeof(CV.Resources.Model.SignUpModel))]
        public string LastName { get; set; }

        [Required]
        [Display(Name = "DateOfBirth", ResourceType = typeof(CV.Resources.Model.SignUpModel))]
        [DisplayFormat(DataFormatString = "d")]
        public DateTime? DateOfBirth { get; set; }

        [Required]
        [Display(Name = "Country", ResourceType = typeof(CV.Resources.Model.SignUpModel))]
        public string Country { get; set; }

        public List<Country> Countries { get; set; }
        public List<string> ErrorMessages { get; set; }

        public User ToEntity()
        {
            return new User()
            {
                Login = Login,
                Password = Password,
                FirstName = FirstName,
                LastName = LastName,
                DateOfBirth = DateOfBirth ?? DateTime.Today,
                Country = null,
            };
        }
    }
}
